/*
 * Copyright (C) 2015 Naman Dwivedi
 *
 * Licensed under the GNU General Public License v3
 *
 * This is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 */

package com.local.videoplayer.ads;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public final class AdPreference {

    private static AdPreference sInstance;

    private static SharedPreferences mPreferences;

    public AdPreference(final Context context) {
        mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    }

    public static final AdPreference getInstance(final Context context) {
        if (sInstance == null) {
            sInstance = new AdPreference(context.getApplicationContext());
        }
        return sInstance;
    }


    public long getLastBigAdTime() {
        if (mPreferences != null) {
            return mPreferences.getLong("lastBigAdTime", 0);
        }
        return 0;
    }

    public long setLastBigAdTime(long time) {
        if (mPreferences != null) {
            mPreferences.edit().putLong("lastBigAdTime", time)
                    .commit();
        }
        return 0;
    }

    public long getLastSmallAdTime() {
        if (mPreferences != null) {
            return mPreferences.getLong("lastSmallAdTime", 0);
        }
        return 0;
    }

    public long setLastSmallAdTime(long time) {
        if (mPreferences != null) {
            mPreferences.edit().putLong("lastSmallAdTime", time)
                    .commit();
        }
        return 0;
    }

    public long setLongValue(String key, long time) {
        if (mPreferences != null) {
            mPreferences.edit().putLong(key, time)
                    .commit();
        }
        return 0;
    }

    public long getLongValue(String key, long time) {
        if (mPreferences != null) {
            return mPreferences.getLong(key, time);
        }
        return 0;
    }
}